package chat.client;

import java.io.*;

import chat.serverToClientMessage.ServerToClientMessage;

/**
 * 
 * @author Marius Eichenberg
 * started by a Client: only one ListenThread for a Client
 * this thread always listens to the ObjectInputStream
 * the messages are handled by processOnClient
 */
public class ListenThread extends Thread {
	
	private ObjectInputStream i;
	private Client client;

	
	/**
	 * constructor creates ListenThread to communicate via a ObjectInputStream 
	 * @param i
	 */
	ListenThread(Client client, ObjectInputStream i){
		this.i = i;
		this.client = client;
	}

	
	/**
	 * run - Method of Thread to run the Thread
	 */
	public void run() {
		while(true){
			try{
				ServerToClientMessage message = (ServerToClientMessage) i.readObject();
				message.processOnClient(client);
			}catch(Exception e){
				System.out.println(e);
			}
		}
	}
}
